<%@include file="/WEB-INF/templates/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>


<h2>${pageTitle}</h2>
<p>${topicBody}</p>
<c:choose>
    <c:when test="${aantalForumThreads != 0}">
        <!-- Wanneer er forums opgeslagen zijn, worden ze hier getoond -->
        <table class="zebra">
            <!-- Child topics  --> 
            <tr>
                <th>
                    <strong>Topics</strong>
                </th>
                <th>
                    <strong></strong>
                </th>
                <th>
                </th>
            </tr>
            <c:forEach var="topic" items="${topics}">
                <c:choose>
                    <c:when test="${topic.forumtopic_isdeleted == 0}">
                        <tr>
                            <td>
                                <a href="${url}forum/topic_view?topic_id=${topic.forumtopicid}">${topic.forumtopicname}</a>
                            </td>
                            <td>
                                
                                <c:set var="body" value="${topic.forumtopicbody}"/>
                                    <c:choose>
                                        <c:when test="${fn:length(body) > 100}">
                                            ${fn:substring(body, 0, 100)}...                                     
                                        </c:when>
                                        <c:otherwise>
                                            $${topic.forumtopicbody}

                                        </c:otherwise>
                                    </c:choose>
                            </td>
                            <td>
                                <a class="icon view" href="${url}forum/topic_view?topic_id=${topic.forumtopicid}">${topic.forumtopicname}</a>
                                <c:choose>
                                    <c:when test="${topic.user.userId == currentUserId}">
                                        <a class="icon delete" title="Delete topic" href="${url}forum/delete_topic?topic_id=${topic.forumtopicid}"></a>

                                    </c:when>
                                    <c:when test="${currentUserType == 3}">
                                        <a class="icon delete" title="Admin delete topic" href="${url}forum/admin_delete_topic?topic_id=${topic.forumtopicid}"></a>
                                    </c:when>

                                </c:choose>


                            </td>
                        </tr>

                    </c:when>

                </c:choose>
            </c:forEach>

            <!-- Child threads  -->
            <tr>
                <th>
                    <strong>Threads</strong>
                </th>
                <th>
                    <strong></strong>
                </th>
                <th>
                </th>

            </tr>
            <c:forEach var="threads" items="${threads}">
                <c:choose>
                    <c:when test="${threads.forumthread_isdeleted == 0}">
                        <tr>
                            <td width="120px;">
                                <a href="${url}forum/thread_view?thread_id=${threads.forumThreadId}">${threads.forumThreadName}</a>
                            </td>
                            <td>
                               
                                <c:set var="body" value=" ${threads.forumThreadBody}"/>
                                    <c:choose>
                                        <c:when test="${fn:length(body) > 100}">
                                            ${fn:substring(body, 0, 100)}...                                     
                                        </c:when>
                                        <c:otherwise>
                                            ${threads.forumThreadBody}

                                        </c:otherwise>
                                    </c:choose>
                            </td>
                            <td>
                                <a class="icon view" href="${url}forum/thread_view?thread_id=${threads.forumThreadId}">${threads.forumThreadName}</a>
                                <c:choose>
                                    <c:when test="${threads.user.userId == currentUserId}">
                                        <a class="icon delete" title="Delete thread" href="${url}forum/delete_thread?thread_id=${threads.forumThreadId}"></a>

                                    </c:when>
                                    <c:when test="${currentUserType == 3}">
                                        <a class="icon delete" title="Admin delete thread" href="${url}forum/admin_delete_thread?thread_id=${threads.forumThreadId}"></a>
                                    </c:when>

                                </c:choose>
                            
                            
                            </td>

                        </tr>
                    </c:when>

                </c:choose>
            </c:forEach>
        </table>
    </c:when>
    <c:otherwise>
        <!-- Als er geen gebruikers zijn, wordt deze melding getoond -->
        There are no threads or topics found in this topic.
    </c:otherwise>
</c:choose>
<p>
    <a class="button" href="${url}forum/topic_add?parenttopic_id=${parentTopic}">Start new topic here</a>
</p>
<p>
    <a class="button" href="${url}forum/thread_add?parenttopic_id=${parentTopic}">Start new thread here</a>
</p>
<p>
    <a class="button" href="${url}index">Go back to the course</a>
</p>